//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.trace;

import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class av {
    private static Context a;
    private static final Set<String> b = new HashSet();
    private static final Set<String> c = new HashSet();
    private static av d;
    private static av.a e;

    public static synchronized av a() {
        if(d == null) {
            d = new av();
            String var0;
            if(VERSION.SDK_INT < 21) {
                var0 = Build.CPU_ABI;
            } else {
                var0 = Build.SUPPORTED_ABIS[0];
            }

            av.a var10000;
            if(var0 == null) {
                var10000 = av.a.a;
            } else {
                if(var0.contains("arm") && var0.contains("v7")) {
                    e = av.a.b;
                }

                if(var0.contains("arm") && var0.contains("64")) {
                    e = av.a.c;
                }

                if(var0.contains("x86")) {
                    if(var0.contains("64")) {
                        e = av.a.e;
                    } else {
                        e = av.a.d;
                    }
                }

                var10000 = e;
            }

            e = var10000;
        }

        return d;
    }

    private av() {
    }

    public static void a(Context var0) {
        if(a == null) {
            a = var0;
        }

    }

    public final synchronized boolean a(String var1) {
        try {
            Set var2 = b;
            synchronized(b) {
                if(b.contains(var1)) {
                    return true;
                }
            }

            System.loadLibrary(var1);
            var2 = b;
            synchronized(b) {
                b.add(var1);
            }

            return true;
        } catch (Throwable var7) {
            String var3 = System.mapLibraryName(var1);
            boolean var4 = false;
            switch(av.SyntheticClass_1.a[e.ordinal()]) {
                case 1:
                    var4 = !this.a(var3, av.a.c)?this.a(var1, var3):this.d(var3, var1);
                    break;
                case 2:
                    var4 = this.a(var1, var3);
                    break;
                case 3:
                    var4 = this.b(var1, var3);
                    break;
                case 4:
                    var4 = !this.a(var3, av.a.e)?this.c(var1, var3):this.d(var3, var1);
                    break;
                case 5:
                    var4 = this.c(var1, var3);
            }

            return var4;
        }
    }

    private boolean a(String var1, String var2) {
        return !this.a(var2, av.a.b)?this.b(var1, var2):this.d(var2, var1);
    }

    private boolean b(String var1, String var2) {
        return this.a(var2, av.a.a)?this.d(var2, var1):false;
    }

    private boolean c(String var1, String var2) {
        return !this.a(var2, av.a.d)?this.a(var1, var2):this.d(var2, var1);
    }

    private boolean d(String var1, String var2) {
        try {
            System.load((new File(b(), var1)).getAbsolutePath());
            Set var7 = b;
            synchronized(b) {
                b.add(var2);
            }

            return true;
        } catch (Throwable var6) {
            Set var3 = c;
            synchronized(c) {
                c.add(var2);
            }

            a(var6);
            return false;
        }
    }

    private boolean a(String var1, av.a var2) {
        StringBuilder var10000 = new StringBuilder();
        StringBuilder var3;
        (var3 = new StringBuilder()).append("lib/").append(var2.b()).append("/");
        String var18 = var10000.append(var3.toString()).append(var1).toString();
        ZipFile var20 = null;
        boolean var10 = false;

        label109: {
            label108: {
                try {
                    var10 = true;
                    var20 = new ZipFile(8 <= VERSION.SDK_INT?a.getPackageCodePath():"");
                    File var17 = new File(b(), var1);
                    ZipEntry var19;
                    if((var19 = var20.getEntry(var18)) == null) {
                        var10 = false;
                        break label108;
                    }

                    a(var20.getInputStream(var19), new FileOutputStream(var17));
                    var10 = false;
                } catch (Exception var15) {
                    Log.e(av.class.getSimpleName(), "copyError", var15);
                    var10 = false;
                    break label109;
                } finally {
                    if(var10) {
                        if(var20 != null) {
                            try {
                                var20.close();
                            } catch (IOException var11) {
                                return false;
                            }
                        }

                    }
                }

                try {
                    var20.close();
                    return true;
                } catch (IOException var14) {
                    return false;
                }
            }

            try {
                var20.close();
                return false;
            } catch (IOException var13) {
                return false;
            }
        }

        if(var20 != null) {
            try {
                var20.close();
            } catch (IOException var12) {
                return false;
            }
        }

        return false;
    }

    private static String b() {
        File var0;
        (var0 = new File(a.getFilesDir(), "libs")).mkdirs();
        return var0.getAbsolutePath();
    }

    private static void a(Throwable var0) {
        Log.e(av.class.getSimpleName(), "loadException", var0);
        Iterator var2 = c.iterator();

        while(var2.hasNext()) {
            String var1 = (String)var2.next();
            Log.e(av.class.getSimpleName(), var1 + " Failed to load.");
        }

    }

    private static void a(InputStream var0, FileOutputStream var1) throws IOException {
        byte[] var2 = new byte[4096];

        try {
            int var3;
            while((var3 = var0.read(var2)) != -1) {
                var1.write(var2, 0, var3);
            }

            var1.flush();
        } finally {
            try {
                var0.close();
            } catch (IOException var10) {
                return;
            }

            try {
                var1.close();
            } catch (IOException var9) {
                return;
            }
        }

    }

    static {
        e = av.a.a;
    }

    static enum a {
        a("armeabi"),
        b("armeabi-v7a"),
        c("arm64-v8a"),
        d("x86"),
        e("x86_64");

        private String f;

        public static av.a[] a() {
            return (av.a[])g.clone();
        }

        private a(String var3) {
            this.f = var3;
        }

        public final String b() {
            return this.f;
        }
    }
}
